using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using MobileClient.UIProcessService;

namespace MobileClient
{
	/// <summary>
	/// Summary description for ctlNumberEntryNA.
	/// </summary>
	public class ctlNumberEntryNA : Control
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.TabControl tabControl;
		private System.Windows.Forms.TabPage tabNumber;
		private System.Windows.Forms.TabPage tabNA;
		private System.Windows.Forms.Button btnMinus;
		private System.Windows.Forms.Button btnZero;
		private System.Windows.Forms.Button btnPeriod;
		private System.Windows.Forms.Button btnNine;
		private System.Windows.Forms.Button btnEight;
		private System.Windows.Forms.Button btnSeven;
		private System.Windows.Forms.Button btnSix;
		private System.Windows.Forms.Button btnFive;
		private System.Windows.Forms.Button btnFour;
		private System.Windows.Forms.Button btnThree;
		private System.Windows.Forms.Button btnTwo;
		private System.Windows.Forms.Button btnOne;
		private System.Windows.Forms.TextBox txtNumber;
		private System.Windows.Forms.CheckBox chkNA;

		private NumberEntryNA m_objEntry;
		private int m_nSelected = 0;

		public ctlNumberEntryNA()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			m_objEntry = null;
		}

		public NumberEntryNA Entry
		{
			get { return m_objEntry; }
			set { m_objEntry = value; }
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tabControl = new System.Windows.Forms.TabControl();
			this.tabNumber = new System.Windows.Forms.TabPage();
			this.tabNA = new System.Windows.Forms.TabPage();
			this.btnMinus = new System.Windows.Forms.Button();
			this.btnZero = new System.Windows.Forms.Button();
			this.btnPeriod = new System.Windows.Forms.Button();
			this.btnNine = new System.Windows.Forms.Button();
			this.btnEight = new System.Windows.Forms.Button();
			this.btnSeven = new System.Windows.Forms.Button();
			this.btnSix = new System.Windows.Forms.Button();
			this.btnFive = new System.Windows.Forms.Button();
			this.btnFour = new System.Windows.Forms.Button();
			this.btnThree = new System.Windows.Forms.Button();
			this.btnTwo = new System.Windows.Forms.Button();
			this.btnOne = new System.Windows.Forms.Button();
			this.txtNumber = new System.Windows.Forms.TextBox();
			this.chkNA = new System.Windows.Forms.CheckBox();
			// 
			// tabControl
			// 
			this.tabControl.Controls.Add(this.tabNumber);
			this.tabControl.Controls.Add(this.tabNA);
			this.tabControl.Location = new System.Drawing.Point(3, 6);
			this.tabControl.SelectedIndex = 0;
			this.tabControl.Size = new System.Drawing.Size(230, 140);
			this.tabControl.SelectedIndexChanged +=new EventHandler(tabControl_SelectedIndexChanged);
			// 
			// tabNumber
			// 
			this.tabNumber.Controls.Add(this.btnMinus);
			this.tabNumber.Controls.Add(this.btnZero);
			this.tabNumber.Controls.Add(this.btnPeriod);
			this.tabNumber.Controls.Add(this.btnNine);
			this.tabNumber.Controls.Add(this.btnEight);
			this.tabNumber.Controls.Add(this.btnSeven);
			this.tabNumber.Controls.Add(this.btnSix);
			this.tabNumber.Controls.Add(this.btnFive);
			this.tabNumber.Controls.Add(this.btnFour);
			this.tabNumber.Controls.Add(this.btnThree);
			this.tabNumber.Controls.Add(this.btnTwo);
			this.tabNumber.Controls.Add(this.btnOne);
			this.tabNumber.Controls.Add(this.txtNumber);
			this.tabNumber.Location = new System.Drawing.Point(4, 22);
			this.tabNumber.Size = new System.Drawing.Size(222, 114);
			this.tabNumber.Text = "Number";
			// 
			// tabNA
			// 
			this.tabNA.Controls.Add(this.chkNA);
			this.tabNA.Location = new System.Drawing.Point(4, 22);
			this.tabNA.Size = new System.Drawing.Size(222, 114);
			this.tabNA.Text = "N/A";
			// 
			// btnMinus
			// 
			this.btnMinus.Location = new System.Drawing.Point(166, 85);
			this.btnMinus.Size = new System.Drawing.Size(40, 20);
			this.btnMinus.Text = "-";
			this.btnMinus.Click += new System.EventHandler(this.btnMinus_Click);
			// 
			// btnZero
			// 
			this.btnZero.Location = new System.Drawing.Point(66, 85);
			this.btnZero.Size = new System.Drawing.Size(40, 20);
			this.btnZero.Text = "0";
			this.btnZero.Click += new System.EventHandler(this.btnZero_Click);
			// 
			// btnPeriod
			// 
			this.btnPeriod.Location = new System.Drawing.Point(116, 85);
			this.btnPeriod.Size = new System.Drawing.Size(40, 20);
			this.btnPeriod.Text = ".";
			this.btnPeriod.Click += new System.EventHandler(this.btnPeriod_Click);
			// 
			// btnNine
			// 
			this.btnNine.Location = new System.Drawing.Point(16, 85);
			this.btnNine.Size = new System.Drawing.Size(40, 20);
			this.btnNine.Text = "9";
			this.btnNine.Click += new System.EventHandler(this.btnNine_Click);
			// 
			// btnEight
			// 
			this.btnEight.Location = new System.Drawing.Point(166, 61);
			this.btnEight.Size = new System.Drawing.Size(40, 20);
			this.btnEight.Text = "8";
			this.btnEight.Click += new System.EventHandler(this.btnEight_Click);
			// 
			// btnSeven
			// 
			this.btnSeven.Location = new System.Drawing.Point(116, 61);
			this.btnSeven.Size = new System.Drawing.Size(40, 20);
			this.btnSeven.Text = "7";
			this.btnSeven.Click += new System.EventHandler(this.btnSeven_Click);
			// 
			// btnSix
			// 
			this.btnSix.Location = new System.Drawing.Point(66, 61);
			this.btnSix.Size = new System.Drawing.Size(40, 20);
			this.btnSix.Text = "6";
			this.btnSix.Click += new System.EventHandler(this.btnSix_Click);
			// 
			// btnFive
			// 
			this.btnFive.Location = new System.Drawing.Point(16, 61);
			this.btnFive.Size = new System.Drawing.Size(40, 20);
			this.btnFive.Text = "5";
			this.btnFive.Click += new System.EventHandler(this.btnFive_Click);
			// 
			// btnFour
			// 
			this.btnFour.Location = new System.Drawing.Point(166, 37);
			this.btnFour.Size = new System.Drawing.Size(40, 20);
			this.btnFour.Text = "4";
			this.btnFour.Click += new System.EventHandler(this.btnFour_Click);
			// 
			// btnThree
			// 
			this.btnThree.Location = new System.Drawing.Point(116, 37);
			this.btnThree.Size = new System.Drawing.Size(40, 20);
			this.btnThree.Text = "3";
			this.btnThree.Click += new System.EventHandler(this.btnThree_Click);
			// 
			// btnTwo
			// 
			this.btnTwo.Location = new System.Drawing.Point(66, 37);
			this.btnTwo.Size = new System.Drawing.Size(40, 20);
			this.btnTwo.Text = "2";
			this.btnTwo.Click += new System.EventHandler(this.btnTwo_Click);
			// 
			// btnOne
			// 
			this.btnOne.Location = new System.Drawing.Point(16, 37);
			this.btnOne.Size = new System.Drawing.Size(40, 20);
			this.btnOne.Text = "1";
			this.btnOne.Click += new System.EventHandler(this.btnOne_Click);
			// 
			// txtNumber
			// 
			this.txtNumber.Location = new System.Drawing.Point(5, 9);
			this.txtNumber.Size = new System.Drawing.Size(212, 20);
			this.txtNumber.Text = "";
			// 
			// chkNA
			// 
			this.chkNA.Location = new System.Drawing.Point(59, 45);
			this.chkNA.Text = "Not Applicable";
			// 
			// ctlNumberEntryNA
			// 
			this.Controls.Add(this.tabControl);
			this.Size = new System.Drawing.Size(236, 152);

		}
		#endregion

		private void btnOne_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "1";
		}

		private void btnTwo_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "2";
		}

		private void btnThree_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "3";
		}

		private void btnFour_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "4";
		}

		private void btnFive_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "5";
		}

		private void btnSix_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "6";
		}

		private void btnSeven_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "7";
		}

		private void btnEight_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "8";
		}

		private void btnNine_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "9";
		}

		private void btnPeriod_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += ".";
		}

		private void btnZero_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "0";
		}

		private void btnMinus_Click(object sender, System.EventArgs e)
		{
			txtNumber.Text += "-";
		}

		public void LoadSettings()
		{
			tabControl.SelectedIndex = 0;

			if(m_objEntry != null)
			{
                if (!String.IsNullOrEmpty(m_objEntry.NumberValue))
                {
                    txtNumber.Text = m_objEntry.NumberValue;
                }
                else
                {
                    txtNumber.Text = "";
                }
				chkNA.Checked = m_objEntry.NotApplicable;
			}
		}

		public void SaveSettings()
		{
			if(m_objEntry != null)
			{
				m_objEntry.NumberValue = txtNumber.Text;
				m_objEntry.NotApplicable = chkNA.Checked;
			}
		}

		private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
		{
			int nIndex = tabControl.SelectedIndex;
			tabControl.TabPages[m_nSelected].Visible = false;			
			tabControl.TabPages[nIndex].Visible = true;
			m_nSelected = nIndex;
		}
	}
}
